package com.ruoyi.web.controller.market;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.market.domain.Customer;
import com.ruoyi.market.service.CustomerService;
import com.ruoyi.system.domain.SysCity;
import com.ruoyi.system.domain.SysProvince;
import com.ruoyi.system.service.SysCityService;
import com.ruoyi.system.service.SysProvinceService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户管理控制器
 */
@Controller
@RequestMapping("/market/look")
public class CustomerLookController extends BaseController {

    private String prefix="market/look";

    @Autowired
    private CustomerService customerService;

    @Autowired
    private SysProvinceService provinceService;

    @Autowired
    private SysCityService cityService;

    @RequiresPermissions("market:look:view")
    @GetMapping()
    public String customer(ModelMap mmap){
        //获取省
        List<SysProvince> provinceList = provinceService.list();
        //获取市
        List<SysCity> cityList = cityService.list();
        //获取当前登录用户
        SysUser user = getSysUser();
        mmap.put("provinceList",provinceList);
        mmap.put("cityList",cityList);
        mmap.put("user",user);
        return prefix + "/look";
    }

    /**
     * 查询客户管理信息列表
     */
    @RequiresPermissions("market:look:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Customer customer, ModelMap mmap)
    {
        //获取省
        List<SysProvince> provinceList = provinceService.list();
        //获取市
        List<SysCity> cityList = cityService.list();
        //获取当前登录用户
        SysUser user = getSysUser();
        Integer userid=user.getUserId().intValue();
        mmap.put("user",user);
        mmap.put("provinceList",provinceList);
        mmap.put("cityList",cityList);
        startPage();
        customer.setSysServiceUserId(userid);
        System.out.println(customer);
        List<Customer> list = customerService.queryList(customer);
        System.out.println(list.get(0));
        mmap.put("list",list);
        return getDataTable(list);
    }



//    /**
//     * 导出客户管理信息列表
//     */
//    @RequiresPermissions("market:look:export")
//    @Log(title = "客户管理信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ResponseBody
//    public AjaxResult export(Customer customer)
//    {
//        List<Customer> list = customerService.queryList(customer);
//        ExcelUtil<Customer> util = new ExcelUtil<Customer>(Customer.class);
//        return util.exportExcel(list, "customer");
//    }

//    /**
//     * 客户管理信息
//     */
//    @GetMapping("/add")
//    public String add(ModelMap mmap)
//    {
//        List<SysProvince> provinceList = provinceService.list();
//        List<SysCity> cityList = cityService.list();
//        mmap.put("provinceList",provinceList);
//        mmap.put("cityList",cityList);
//        SysUser user = getSysUser();
//        mmap.put("user",user);
//        return prefix + "/add";
//    }

//    /**
//     * 新增保存客户管理信息
//     */
//    @RequiresPermissions("market:look:add")
//    @Log(title = "客户管理信息", businessType = BusinessType.INSERT)
//    @PostMapping("/add")
//    @ResponseBody
//    public AjaxResult addSave(Customer customer)
//    {
//        return toAjax(customerService.save(customer));
//    }

//    /**
//     * 修改客户管理信息
//     */
//    @GetMapping("/assign/{id}")
//    public String assign(@PathVariable("id") Integer id,ModelMap mmap)
//    {
//        Customer customer = customerService.getById(id);
//        System.out.println(customer);
//        mmap.put("customer", customer);
//
//        List<SysProvince> provinceList = provinceService.list();
//        List<SysCity> cityList = cityService.list();
//        mmap.put("provinceList",provinceList);
//        mmap.put("cityList",cityList);
//        SysUser user = getSysUser();
//        mmap.put("user",user);
//        return prefix + "/assign";
//    }



    /**
     * 客户浏览详情信息
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Integer id,ModelMap mmap)
    {
        Customer customer = customerService.findById(id);
        System.out.println(customer);
        mmap.put("customer", customer);

        List<SysProvince> provinceList = provinceService.list();
        List<SysCity> cityList = cityService.list();
        mmap.put("provinceList",provinceList);
        mmap.put("cityList",cityList);
        SysUser user = getSysUser();
        mmap.put("user",user);
        return prefix + "/detail";
    }

//
//    /**
//     * 修改保存客户管理信息
//     */
//    @RequiresPermissions("market:look:assign")
//    @Log(title = "客户管理信息", businessType = BusinessType.UPDATE)
//    @PostMapping("/assign")
//    @ResponseBody
//    public AjaxResult assignSave(Customer customer)
//    {
//        return toAjax(customerService.updateById(customer));
//    }
//


//    /**
//     * 修改客户管理信息
//     */
//    @GetMapping("/edit/{id}")
//    public String edit(@PathVariable("id") Integer id,ModelMap mmap)
//    {
//        Customer customer = customerService.getById(id);
//        System.out.println(customer);
//        mmap.put("customer", customer);
//
//        List<SysProvince> provinceList = provinceService.list();
//        List<SysCity> cityList = cityService.list();
//        mmap.put("provinceList",provinceList);
//        mmap.put("cityList",cityList);
//        SysUser user = getSysUser();
//        mmap.put("user",user);
//        return prefix + "/edit";
//    }

//    /**
//     * 修改保存客户管理信息
//     */
//    @RequiresPermissions("market:look:edit")
//    @Log(title = "客户管理信息", businessType = BusinessType.UPDATE)
//    @PostMapping("/edit")
//    @ResponseBody
//    public AjaxResult editSave(Customer customer)
//    {
//        return toAjax(customerService.updateById(customer));
//    }
//
//    /**
//     * 删除客户管理信息
//     */
//    @RequiresPermissions("market:look:remove")
//    @Log(title = "客户管理信息", businessType = BusinessType.DELETE)
//    @PostMapping("/remove")
//    @ResponseBody
//    public AjaxResult remove(String ids)
//    {
//        return toAjax(customerService.removeByIds(Arrays.asList(ids)));
//    }
}
